/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.igorov.efficientsoft.business.gestorpago;

import com.igorov.efficientsoft.dataaccess.domain.PagoDAO;
import com.igorov.efficientsoft.dataaccess.model.TpagoVO;
import com.igorov.efficientsoft.dataaccess.model.TpedidoVO;
import com.igorov.efficientsoft.services.PagoDTO;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author igorov
 */
public class GestorPagoImpl implements GestorPago{

    private PagoDAO pagoDAO;

    public PagoDAO getPagoDAO() {
        return pagoDAO;
    }

    public void setPagoDAO(PagoDAO pagoDAO) {
        this.pagoDAO = pagoDAO;
    }

    public List<PagoDTO> getAllByNumeroPedido(int numeroPedido) {
        List<TpagoVO> tpagoVOs = pagoDAO.getAllByNumeroPedido(numeroPedido);
        List<PagoDTO> pagoDTOs = new LinkedList<PagoDTO>();
        for (Iterator<TpagoVO> it = tpagoVOs.iterator(); it.hasNext();) {
            TpagoVO tpagoVO = it.next();
            
            PagoDTO pagoDTO = new PagoDTO();
            pagoDTO.setCodigo(tpagoVO.getNcodPag());
            pagoDTO.setCodPedido(tpagoVO.getTpedido().getNcodPed());
            pagoDTO.setCodUsu(tpagoVO.getNcodUsu());
            pagoDTO.setDiaSiguiente(tpagoVO.getDdiaSig());
            pagoDTO.setDiasRetraso(tpagoVO.getNdiasRet());
            pagoDTO.setFechaPago(tpagoVO.getDfecPag());
            pagoDTO.setInicial(tpagoVO.isLinicial());
            pagoDTO.setMonto(tpagoVO.getdMonto());
            
            pagoDTOs.add(pagoDTO);
        }
        return pagoDTOs;
    }
    
    public void deleteById(int i) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void deleteByIndex(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<PagoDTO> getAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public PagoDTO getById(int voId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public PagoDTO getByIndex(int indice) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getIdAtIndex(int indice) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getIndexOf(int voId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void saveOrUpdate(PagoDTO o) {
        TpagoVO tpagoVO = new TpagoVO();
        
        if (o.getCodigo() != 0) {
            tpagoVO.setNcodPag(o.getCodigo());
        }
        tpagoVO.setDdiaSig(o.getDiaSiguiente());
        tpagoVO.setDfecPag(o.getFechaPago());
        tpagoVO.setLinicial(o.isInicial());
        tpagoVO.setNcodUsu(o.getCodUsu());
        tpagoVO.setdMonto(o.getMonto());
        
        tpagoVO.setNdiasRet(0);
        
        TpedidoVO tpedidoVO = new TpedidoVO();
        tpedidoVO.setNcodPed(o.getCodPedido());
        
        tpagoVO.setTpedido(tpedidoVO);
        
        System.out.println("Datos del pago:");
        System.out.println("Fecha: " + tpagoVO.getDfecPag().toString());
        System.out.println("Fecha siguiente: " + tpagoVO.getDdiaSig().toString());
        System.out.println("Es inicial:" + tpagoVO.isLinicial());
        System.out.println("Dias de retraso: " + tpagoVO.getNdiasRet());
        System.out.println("Codigo de usuario: " + tpagoVO.getNcodUsu());
        System.out.println("Monto del pago: " + tpagoVO.getdMonto());
        System.out.println("Pedido: " + tpagoVO.getTpedido().getNcodPed());
        
        pagoDAO.saveOrUpdate(tpagoVO);
    }

    public void updateListVo() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
